<template>
  <!-- router  启动路由功能 -->
  <el-menu
    :router="true"
    :unique-opened="true"
    class="el-menu-admin"
    @open="handleOpen"
    @close="handleClose"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    :collapse="isShow"
  >
    <div class="btn">
      <i class="el-icon-s-operation" @click="changeMenu"></i>
    </div>
    <el-submenu :index="item.path" v-for="item in menuData" :key="item.id">
      <template slot="title">
        <i class="el-icon-user-solid" @click="changeMenu"></i>
        <span>{{ item.authName }}</span>
      </template>
      <el-menu-item
        :index="tag.path"
        v-for="tag in item.children"
        :key="tag.id"
      >
        <i class="el-icon-menu"></i>
        <span slot="title">{{ tag.authName }}</span>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
import { getMenus } from "@/api/index";
export default {
  data() {
    return {
      menuData: "",
      isShow: false
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    changeMenu() {
      this.isShow = !this.isShow;
    }
  },
  created() {
    getMenus().then(res => {
      if (res.meta.status === 200) {
        this.menuData = res.data;
      }
    });
  }
};
</script>

<style scoped lang="scss">
.el-menu {
  border: 0;
}
.el-menu-item {
  padding: 0;
  text-align: center;
}
.btn {
  text-align: center;
  background-color: rgb(110, 109, 109);
}
.btn i {
  color: white;
  display: block;
  padding: 22px;
}
.el-menu-admin:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
